package org.mydba.report.gui;

import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;

/**
 */
public class HintPanel extends JPanel {

    JLabel msg;

    HintPanel() {
        super(new GridBagLayout());
        setBackground(new Color(253, 254, 226));
        setBorder(new LineBorder(Color.BLACK, 1, false));

        msg = new JLabel("");

        final GridBagConstraints gbc = new GridBagConstraints();

        // Add the text field to the applet.
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.weightx = 1;
        gbc.weighty = 1;
        gbc.anchor = GridBagConstraints.PAGE_START;
        gbc.fill = GridBagConstraints.CENTER;

        add(msg, gbc);

        hideMe();
    }

    public void setMsg(final String m) {
        final StringBuilder sb = new StringBuilder("<html><font size=\"2\" face=\"Courrier\">").append(m);
        msg.setText(sb.toString());
        final Dimension textSize = msg.getPreferredSize();
        setSize(textSize.width + 4, textSize.height + 4);
    }

    public void setLocation(int x, int y) {
        final Dimension d = getSize();

        if (x + d.width > MyDBAReport.FRAME_WIDTH) {
            x = MyDBAReport.FRAME_WIDTH - d.width - 4;
            y += 10;
        }

        if (y + d.height > MyDBAReport.FRAME_HEIGHT) {
            y = MyDBAReport.FRAME_HEIGHT - d.height - 20;
        }

        super.setLocation(x, y);
    }

    public void hideMe() {
        super.setLocation(3000, 3000);
    }
}
